package com.itkaien.javaeebased.demo04;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

public class PokerGame {

    static final List<String> pokerList=new ArrayList<>();
    static {
        System.out.println("加载牌库资源");
        String[] color={"♠","♥","♣","♦"};
        String[] number={"A","2","3","4","5","6","7","8","9","10","J","Q","K"};
        for (String colorOne: color) {
            for (String numberOne: number){
              String oneJoker=colorOne+numberOne;
              pokerList.add(oneJoker);
            }
        }
        pokerList.add("大王");
        pokerList.add("小王");
    }

    public PokerGame() {
        //准备牌
        System.out.println(pokerList);
        //洗牌
        Collections.shuffle(pokerList);
        //发牌
        List<String> lineCard=new ArrayList<>();

        List<String> player1=new ArrayList<>();
        List<String> player2=new ArrayList<>();
        List<String> player3=new ArrayList<>();


        for (int i = 0; i < pokerList.size(); i++) {

            if (i<3){
                lineCard.add(pokerList.get(i));
                continue;
            }
            if (i%3==0){
                player1.add(pokerList.get(i));
            }else if (i%3==1){
                player2.add(pokerList.get(i));
            }else if (i%3==2){
                player3.add(pokerList.get(i));
            }
            if (i==pokerList.size()-1){
                lineCard.add(pokerList.get(i));
            }
        }
        //看牌
        lookPoker("地牌",lineCard);
        lookPoker("玩家1",player1);
        lookPoker("玩家2",player2);
        lookPoker("玩家3",player3);
    }

    public void lookPoker(String name,List<String> list){
        System.out.print(name+"的牌是:");
        for (String card:list) {
            System.out.print(card+" ");
        }
        System.out.println();
    }
}
